#本文件主要是蛇吃的食物类
import pygame
import sys
import random
import time
from src.interface import *

foods = {
    "insect" : pygame.image.load('image/insect.png'),
    "rocket" :pygame.image.load('image/rocket.png'),
    "snails" :pygame.image.load('image/snails.png'),
    "bird": pygame.image.load('image/bird.png'),
}

# 食物类
# 方法： 放置/移除
# 点以25为单位
class Food:
    def __init__(self):
        self.rect = pygame.Rect(-25,0,25,25)
        self.foodtype = "insect"
        self.allfoodtype = list(foods.keys())

    def remove(self):
        self.rect.x=-25
        
    #设置食物类型
    def setfoodtype(self):
        self.foodtype = random.choice(self.allfoodtype)
            
    def set(self, wall):
        if self.rect.x == -25:
            while True:
                allpos = []
                # 不靠墙太近 25 ~ SCREEN_X-25 之间
                for pos in range(25,SCREEN_X-25,25):
                    allpos.append(pos)
                self.rect.left = random.choice(allpos)
                self.rect.top  = random.choice(allpos)
                if self.rect not in wall.wallpos:
                    break

    def foodis(self,food):
        return self.foodtype == food